<template>
	<view class="nx-box" v-if="bg!=''"
		:style="{background:'url('+bg+')',backgroundSize:'contain',backgroundrepeat:'center',backgroundcolor:'#000' }">
		<!-- <image src="https://pc.xuexi.cn/points/study-login/asset/b1ee4724c98f9e94329ad4798065f234.png" mode="aspectFit" class="nx-logo"></image> -->
		<!-- <image src="../../../static/images/100/logo.png" class="nx-logo" mode="aspectFit"></image> -->
		<!-- <view class="nx-title">LOGO区域</view> -->
		<view class="nx-form">
			<view class="nx-input">
				账号：<input placeholder="请输入用户名" v-model="login.loginName" />
			</view>
			<view class="nx-input">
				密码：<input password placeholder="请输入密码" v-model="login.password" />
			</view>
			<!-- <view class="nx-label">忘记密码？</view> -->
			<button class="nx-btn" @tap="loginFunction">立即登录</button>
			<!-- <navigator url="./register" hover-class="none" class="nx-label">还没有账号？点此注册.</navigator> -->
		</view>
		<v-footer></v-footer>
	</view>
</template>

<script>
	import {
		mapActions,
		mapState
	} from 'vuex'
	import footer from '../../components/footer/footer.vue'
	export default {
		components: {
			'v-footer': footer
		},
		onShow() {
			uni.setNavigationBarTitle({
					title: "登陆页面"
				}),
				this.loadPageBg()
		},
		data() {
			return {
				login: {
					loginName: '', //手机号码
					password: '' //密码
				},
				bg: ''
			};
		},
		computed: {
			...mapState(['token', 'userCode'])
		},
		methods: {
			// ...mapActions(['SET_TOKEN','SET_USERCODE']),
			loadPageBg: function() {
				let opts = {
					url: '/api/GetIcon',
					method: 'get'
				};
				this.$request.httpRequest(opts, {}).then(e => {
					// console.log('loadPageBg', e.e.data.PicLogin)
					this.bg = e.data.PicLogin

				}).catch((e) => {
					this.reLogin()
				})
				// uni.request({
				// 	url: `api/GetIcon`,
				// 	complete: 
				// 	},
				// 	fail: () => {
				// 		this.reLogin();
				// 	}
				// });
			},
			//当前登录按钮操作
			loginFunction() {
				let that = this;
				if (!that.login.loginName) {
					uni.showToast({
						title: '请输入账户',
						icon: 'none'
					});
					return;
				}
				if (!that.login.password) {
					uni.showToast({
						title: '请输入密码',
						icon: 'none'
					});
					return;
				}
				let param = {
					userCode: this.login.loginName,
					userPsw: this.login.password
				};
				that.$request.httpRequest({
					url: '/api/Token'
				}, param).then(e => {
					if (e.statusCode === 200) {
						let data = e.data;
						if (!data.Success) {
							uni.showToast({
								icon: 'none',
								title: data.Message
							});
							return false;
						}
						// this.SET_TOKEN(data.Token)
						// this.SET_USERCODE(data.UserCode)
						that.$store.commit('SET_TOKEN', data.Token);
						that.$store.commit('SET_USERCODE', data.UserCode);
						that.$store.commit('SET_USERNAME', data.UserName);
						that.$store.commit('SET_USERPHOTO', data.PhotoUrl)
						// console.log(this.token, this.userCode);
						uni.showToast({
							icon: 'success',
							title: '登陆成功',
							success: () => {
								setTimeout(function() {
									uni.switchTab({
										url: '/pages/index/index', //要跳转的页面
										success: function(e) {
											var page = getCurrentPages()[0]
											if (page == undefined || page ==
												null) {
												return;
											} else {
												// 跳转至下一页面后执行此方法 
												// page.getOrderList('2');
												console.log(page)
												page.onLoad()
												// this.loadBranchs();
												// this.loadTabbarList()
											}
										}
									})

									// uni.switchTab({
									// 	url: '../../index/index',
									// 	fail: (e) => {
									// 		console.log(e);
									// 	}
									// })
								}, 1500);
							}
						});
					} else {
						console.log(this.$configUrl);
						uni.showToast({
							title: '请求失败，请联系管理员',
							icon: 'none'
						});
					}
				})
			}
		}
	};
</script>

<style scoped lang="scss">
	.nx-box {
		position: fixed;
		width: 100%;
		height: 100vh;
		top: 0px;
		background-color: #00BFFF;
		background-repeat: repeat;

		// background: url('@/static/images/100/bg.jpeg') repeat 0rpx 40rpx fixed;
		background-size: 100% 100% !important;
		-webkit-filter: blur(0px);
		z-index: 999;
	}

	.nx-logo {
		width: 90%;
		/* width: 100%; */
		position: fixed;
		top: 20vh;
		width: 100vw;
		// height: 310upx;
	}

	.nx-title {
		position: absolute;
		top: 0;
		line-height: 360upx;
		font-size: 68upx;
		color: #fff;
		text-align: center;
		width: 100%;
		margin-left: -100upx;
	}

	.nx-form {
		margin-top: 55vh;
		position: fixed;
		left: 0vw;
		top: 0vh;
		width: 80vw;
		margin-left: 10vw;
	}

	.nx-input {
		/* background: #e2f5fc; */
		margin-top: 30upx;
		border-radius: 100upx;
		border: 1rpx solid #e2f5fc;
		padding: 20upx 40upx;
		font-size: 36upx;
		box-sizing: content-box;
		color: #FFF;
		z-index: 999;

		input {
			display: inline-block;
			text-align: center;
			position: absolute;
			// pointer-events: none;
		}
	}

	.nx-label {
		padding: 60upx 0;
		text-align: center;
		font-size: 30upx;
		color: #a7b6d0;
	}

	.nx-btn {
		margin-top: 3vh;
		background-color: rgb(205, 0, 0);
		color: rgb(255, 255, 255);
		border: 0;
		border-radius: 100upx;
		font-size: 36upx;
	}

	.nx-btn:after {
		border: 0;
	}

	/*按钮点击效果*/
	.nx-btn.button-hover {
		transform: translate(1upx, 1upx);
	}
</style>
